/*
 * connectionListener.cpp
 *
 */

#include "IPC/Socket.h"

#define BROKER_PORT

int main(int argc, char ** argv)
{
	Socket listener;

	listener.listen(BROKER_PORT);

	while(true)
	{
		file_descriptor fd;

		fd = listener.accept();

		Socket incomming(fd);

		pid_t pid =fork();
		pid_t pid2;

		//Open a new worker
		if(pid == 0)
		{
			pid2 = fork();

			//Do worker stuff
			if(pid2 == 0)
			{
				listener.close();
			}
			else
				return 0;
		}

		else
		{
			wait(pid);
			incomming.close();
		}

	}

	return 0;
}
